<?php

header("Content-type: text/xml");

//$start = (isset($_POST['start'])) ? $_POST['start'] : "0" ;
$dir = (isset($_POST['sortorder'])) ? $_POST['sortorder'] : "ASC" ;
$sort = (isset($_POST['sortname'])) ? $_POST['sortname'] : "description" ;
$rp = (isset($_POST['rp'])) ? $_POST['rp'] : "25" ;
$page = (isset($_POST['page'])) ? $_POST['page'] : "1" ;



$defaults = getSystemDefaults();
$smarty -> assign("defaults",$defaults);

$products = new product();
$sth = $products->getProductsAlertStock('', $dir, $sort, $rp, $page);
$sth_count_rows = $products->getProductsAlertStock('count',$dir, $sort, $rp, $page);

$products_all = $sth->fetchAll(PDO::FETCH_ASSOC);

$count = $sth_count_rows->rowCount();




//echo sql2xml($customers, $count);
$xml .= "<rows>";

$xml .= "<page>$page</page>";

$xml .= "<total>$count</total>";

foreach ($products_all as $row) {

	$xml .= "<row id='".$row['id']."'>";
	$xml .= "<cell><![CDATA[".$row['barCode']."]]></cell>";
	$xml .= "<cell><![CDATA[".$row['description']."]]></cell>";
	$xml .= "<cell><![CDATA[".$row['alertStock']."]]></cell>";
        $xml .= "<cell><![CDATA[ <div style='font-weight:bold; color:#FF0000'>".siLocal::number_clean($row['currentStock'])."</div>]]></cell>";
        
	$xml .= "</row>";		
}

$xml .= "</rows>";

echo $xml;

?> 
